package com.erpanderp.pr.model.entity

import com.erpanderp.pr.util.Constants

class User {
	static hasMany=[purchaseRequests:PurchaseRequest,userRoles:UserRole]
	String employeeNumber
	String firstName
	String lastName
	String email
	String password
	String securityQuestion
	String securityAnswer
	String status=Constants.USER_ACCOUNT_STATUS_IN_PROCESS
	String roleName
	
	Date dateCreated		
	Date lastUpdated	
	String createdBy
	String lastUpdatedBy
	
	def beforeInsert = {
        password = password.encodeAsSHA()
    }

    static constraints = {
    	employeeNumber(unique:true)
    	password(blank:false, password:true)
    	firstName(blank:false)
    	lastName()
    	email(email:true)
    	securityQuestion(inList:[Constants.SECURITY_QUESTION_CHILDHOOD_NICKNAME, Constants.SECURITY_QUESTION_BIRTH_TOWN, Constants.SECURITY_QUESTION_BIRTH_HOSPITAL, Constants.SECURITY_QUESTION_6TH_GRADE_SCHOOL, Constants.SECURITY_QUESTION_MOTHER_MAIDEN_NAME])
    	securityAnswer(blank:false)
    	status(inList:[Constants.USER_ACCOUNT_STATUS_IN_PROCESS, Constants.USER_ACCOUNT_STATUS_APPROVED])
    }
}
